package ru.budget.mobile.core

sealed class Response<out T> (open val state: ResponseStates) {

    fun <R> map(mapper: ((T) -> R)): Response<R> =
        when(this) {
            is Success -> Success(data = mapper(this.data), state = state)

            is Loading -> Loading(state = state)

            is Error -> Error(exception = exception, state = state)
        }

    class Success<T>(val data: T, override val state: ResponseStates): Response<T>(state)

    class Loading(override val state: ResponseStates): Response<Nothing>(state)

    class Error(val exception: Exception, override val state: ResponseStates): Response<Nothing>(state)
}